

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;

/**
 * process class. holds all variables of a process.
 * @author Patrick Black, Archana Ragunath
 * 
 *
 */
public class Process {
	public enum procState { RUNNING, READY, BLOCKED }
	public String name;
	//public int arrivalTime;
	public int runTime;
	public String userName;
	//public int remainingTime;
	private int priority;
	private int currentPriority;
	protected String systemCall;
	protected int[] sysCallInstruction = new int[400];
	int	no_steps;		// number of time steps before resetting to 0 - number of instructions
	
 
	int	procId;
	int next_step;		// this is the step count that the CPU had gotten to when this process was
						// prempted (like a PC register value)
	procState state;			// e.g. 0=running, 1=ready, 2=interrupted, 3=blocked
	//Process proc;    // pointer to the actual process
	int waiting_on;		// which queue is it in if it is waiting on something (blocked)
	//int owns;			// which mutex lock does it own
/*
public Process(String name, int arrivalTime, int runTime, String userName){
	
	this.name = name;
	this.arrivalTime = arrivalTime;
	this.runTime = runTime;
	this.userName = userName;
	this.remainingTime = runTime;
	this.priority = priority;
	this.currentPriority = priority;
	this.state = procState.READY;
	this.no_steps = runTime;
	
}*/

	/**
	 * 
	 * @param name name of process
	 * @param runTime amount of instructions in process
	 * @param priority priority of process
	 * @param systemCall which system call is used.
	 */
public Process(String name, int runTime, int priority, String systemCall) {
	this.name = name;
	this.next_step = 0;
	this.no_steps = runTime;
	this.priority = priority;
	this.currentPriority = priority;
	this.systemCall = systemCall;
	for(int i =0; i < 400; i++) {
		sysCallInstruction[i] = 0 + (int)(Math.random()*runTime);
	}
	
	this.state = procState.READY;
	this.waiting_on = -1;
}

/**
 * 
 * @param x address of instruction for system call
 * @return 1 if pc calls system call, -1 if not
 */
public int getSysCallInstruction(int x) {
	int pc = -1;
	for(int i = 0; i < 400; i++) {
		if(sysCallInstruction[1] == x)
		 pc = 1;
	}
	return pc;
}

/**
 * 
 * @return which system call is used.
 */
public String getSystemCall() {
	return systemCall;
}

/**
 * 
 * @return the next instruction.
 */
public int fetchnxtStep(){
    return next_step;
}

/**
 * 
 * @return total instructions
 */
public int fetchnoStep(){
    return no_steps;
}

/**
 * 
 * @param ns the next instruction.
 */
public void setnxtStep(int ns){
    this.next_step = ns;
}

/**
 * 
 * @return current state of the process.
 */
public procState fetchState(){
    return state;
}  

/**
 * 
 * @param ns the soon to be current state of the process.
 */
public void setState(procState ns){
    this.state = ns;
}

/**
 * 
 * @return the name of the process.
 */
public String fetchName(){
    return name;
}

/**
 * 
 * @param i memory location producer/consumer to wait on.
 */
public void setWaitingOn(int i) {
	this.waiting_on = i;
}

/**
 * 
 * @return memory location producer/consumer is waiting on.
 */
public int getWaitingOn() {
	return this.waiting_on;
}

/**
 * lowers the priority by 5 unless already at 5 then increase to max.
 */
public void changePriority() {
	if(currentPriority > 5) {
		currentPriority = currentPriority - 5;
	} else {
		 currentPriority = priority;
	}
}

/**
 * 
 * @return current priority.
 */
public int getPriority() {
	return currentPriority;
}

public String toString() {
	return this.name;
	
}


/*
	public enum procType { UI, CALCULATOR, PRODUCER, CONSUMER }
	
	procType currType;
	
	


	public int fetchprocId(){
    return procId;
}
	 
	  
		
		
	    public void procControlBlock(int pid, Process rcvdProc){
	    	procId = pid;
	        next_step = 0;
	        state = procState.READY;
	        proc = rcvdProc;
	        waiting_on = 0;
	        owns = 0;


	}
	    
	    
	    public Process getProcess(){
	        return proc;
	}
	    
	    public int fetchgetWaitOn(){
	        return waiting_on;
	}
	    
	    public void setWaitOn(int wo){
	        this.waiting_on = wo;
	}
	    
	   
	    
	    public int fetchWhoOwns(){
	        return owns;
	}
	    
	    public void setWhoOwns(int ow){
	        this.owns = ow;
	}
	    
	   


public void run(int runTimes){
	
	remainingTime -= runTimes;
	System.out.println(this.name + " is Running for " + runTimes + " times.");
		
}*/
}


